package com.wb.mas.ui.login;

import android.content.Intent;
import android.os.Bundle;

import com.wb.mas.BR;
import com.wb.mas.R;
import com.wb.mas.app.AppViewModelFactory;
import com.wb.mas.databinding.ActLoginByPhone2Binding;
import com.wb.mas.ui.main.MainActivity;

import androidx.lifecycle.Observer;
import androidx.lifecycle.ViewModelProviders;

import me.goldze.mvvmhabit.base.BaseActivity;

public class LoginByPhoneStep2Ac extends BaseActivity<ActLoginByPhone2Binding, LoginByPhoneViewModel2> {
    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.act_login_by_phone2;
    }

    @Override
    public int initVariableId() {
        return BR.loginByPhoneViewModel;
    }


    @Override
    public LoginByPhoneViewModel2 initViewModel() {
        //使用自定义的ViewModelFactory来创建ViewModel，如果不重写该方法，则默认会调用LoginViewModel(@NonNull Application application)构造方法
        AppViewModelFactory factory = AppViewModelFactory.getInstance(getApplication());
        LoginByPhoneViewModel2 loginByPhoneViewModel2 = ViewModelProviders.of(this, factory).get(LoginByPhoneViewModel2.class);
        loginByPhoneViewModel2.setPhoneNum(getIntent().getStringExtra("phone_num"));
        return loginByPhoneViewModel2;
    }

    @Override
    public void initViewObservable() {
        super.initViewObservable();
        viewModel.ui.loginSucEvent.observe(this, new Observer<String>() {
            @Override
            public void onChanged(String s) {

                Intent mainIntent = new Intent(LoginByPhoneStep2Ac.this, MainActivity.class);
                LoginByPhoneStep2Ac.this.startActivity(mainIntent);
            }
        });
    }
}
